﻿package com.kingt.social.util;

import android.util.Log;

public class LogUtil {

	public static class log {
		public static String Tag = "socail_log";
		public static final boolean show = true;
		public static final boolean isCostomTag = false;
		public static String Cname = "";
		public static String Mname = "";

		protected static String getClassName() {
			StackTraceElement caller = new Throwable().fillInStackTrace()
					.getStackTrace()[2];

			String className = new StringBuilder()
					.append(caller.getClassName()).toString();
			className = className.substring(className.lastIndexOf(".") + 1);
			Cname = className;
			Mname = new StringBuilder().append(
					caller.getMethodName() + "->" + caller.getLineNumber()
							+ ": ").toString();
			return className;
		}

		protected static String getMethodName() {
			StackTraceElement caller = new Throwable().fillInStackTrace()
					.getStackTrace()[2];

			return new StringBuilder().append(
					caller.getMethodName() + "->" + caller.getLineNumber()
							+ ": ").toString();
		}

		protected static void getTrace() {
			StackTraceElement caller = new Throwable().fillInStackTrace()
					.getStackTrace()[2];

			String className = new StringBuilder()
					.append(caller.getClassName()).toString();
			className = className.substring(className.lastIndexOf(".") + 1);
			Cname = className;
			Mname = new StringBuilder().append(
					caller.getMethodName() + "->" + caller.getLineNumber()
							+ ": ").toString();
		}

		public static void d(String text) {
			if (!show) {
				return;
			} else {
				getTrace();
				if (!isCostomTag) {
					Tag = Cname;
				}
				if (null == text) {
					text = "null";
				}
				if (log.show) {
					Log.d(Tag, Mname + text);
				}

			}
		}

		public static void e(String text) {
			if (!show) {
				return;
			} else {
				getTrace();
				if (!isCostomTag) {
					Tag = Cname;
				}
				if (null == text) {
					text = "null";
				}
				if (log.show) {
					Log.e(Tag, Mname + text);
				}

			}

		}

		public static void d(int text) {
			d("" + text);
		}

		public static void d(float text) {
			d("" + text);
		}

		public static void d(double text) {
			d("" + text);
		}

		public static void d() {
			if (!show) {
				return;
			} else {
				getTrace();
				if (!isCostomTag) {
					Tag = Cname;
				}
				if (log.show)
					Log.d(Tag, Mname + "");

			}
		}

		public static void e() {
			if (!show) {
				return;
			} else {
				getTrace();
				if (!isCostomTag) {
					Tag = Cname;
				}
				if (log.show)
					Log.e(Tag, Mname + "");

			}

		}

		public static void e(String text, Exception e) {
			if (!show) {
				return;
			}
			if (!isCostomTag) {
				Tag = Cname;
			}
			String tmp = text + Mname + "err:" + e.toString();
			if (log.show)
				Log.e(Tag, tmp);
			e.printStackTrace();
		}

		public static void d(String Tag, String text) {
			if (!show) {
				return;
			} else {
				getTrace();
				if (log.show)
					Log.d(Tag, Cname + "->" + Mname + text);
			}

		}

		public static void e(String Tag, String text, Exception e) {
			if (!show) {
				return;
			} else {
				getTrace();
				if (log.show)
					Log.e(Tag,
							Cname + "->" + Mname + text + " err:"
									+ e.toString());
			}

		}
	}

}
